#pragma once

#include <QDate>
#include <QTime>
#include <QPainter>

#include "QSpongeMuscle.h"
#include "QPotentialMuscle.h"
#include "QNode.h"

#include "src/QPropertyWidget.h"
#include "src/QXmlModelHandler.h"
#include "src/QNeuronWindow/QNeuronWindow.h"

#include "ConnectionStruct.h"

class QMuscleWindow: public QMainWindow
{
    Q_OBJECT
private:
    QPropertyWidget *propertyWidget;
    QWidget *centralWidget;

    QList <QNode*> nList;
    QList <QAbstractMuscle*> mList;
    QList <CONNECTION> connectionList;

    int selNode;
    int selMuscle;
    bool moveMode;
    int moveNode;
    bool wasFixed;

    int gridStep;
    bool hasBinding;

    QPointF tempPos;
    int mode;

    bool leftButtonPressed;

    QTimer *timer;

    QAction *newAction;
    QAction *saveAction;
    QAction *loadAction;
    QAction *startAction;
    QAction *stopAction;
    QAction *exitAction;

    QAction *freeAction;
    QAction *nodeAction;
    QAction *spongeMuscleAction;
    QAction *potentialMuscleAction;

    QAction *helpAction;
    QAction *aboutAction;
    QAction *aboutQtAction;

    QMenu *fileMenu;
    QMenu *modeMenu;
    QMenu *viewMenu;
    QMenu *aboutMenu;

    QLabel *statusLabel;

protected:
    void setDefaults(void);

    void paintEvent(QPaintEvent * /*event*/ );
    void mousePressEvent(QMouseEvent *event);
    void mouseDoubleClickEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void resizeEvent(QResizeEvent * /*event*/ );
    void closeEvent (QCloseEvent * /*event*/ );

    void addNode(QPointF pos);
    void addMuscle(QNode* node_1, QNode* node_2);

    void catchNode(QPointF pos);

    void createActions(void);
    void createMenus(void);
    void createStatusBar(void);

    void buildPropertyWidget(void);
    void fillPropertyWidget(void);

    QDomElement xmlAddNode(QDomDocument* xmlFile, QNode* node);
    QDomElement xmlAddConnection(QDomDocument* xmlFile, CONNECTION connection);
    QDomElement xmlAddMuscle(QDomDocument* xmlFile, QAbstractMuscle* muscle);

public:
    QMuscleWindow(void);

public slots:
    void setAllowedSize(void);

    void calc(void);

    void addConnection(int node);
    void removeConnection(int sender, int senderChannel, int receiver);
    void removeConnectionsByNodeID(int id);
    void editNetwork(int node);

    void removeNode(int node);
    void removeMuscle(int muscle);

    void selectNode(int node);
    void selectMuscle(int muscle);

    void setGridStep(int _gridStep);
    void setBinding(bool _hasBinding);

    void reset(void);
    void save(void);
    void load(void);
    void start(void);
    void stop(void);
    void exit(void);

    void setMode0(void);	//free mode
    void setMode1(void);	//add node mode
    void setMode2(void);	//add sponge muscle mode
    void setMode3(void);	//add potential muscle mode

    void help(void);
    void about(void);
    void aboutQt(void);

signals:
    void closeSignal(void);
    void resetSignal(void);

};
